package com.dog.basics.api.controller.common;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.api.common.ApiNewsReadAddDto;
import com.dog.basics.bean.vo.api.common.ApiNewsVo;
import com.dog.basics.common.constant.SwaggerConstants;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.service.common.IDogNewsReadService;
import com.dog.basics.service.common.IDogNewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 消息通知 前端控制器
 * </p>
 *
 * @author guonh
 * @since 2020-05-14
 */
@RestController
@RequestMapping("/api/news")
@Api(value = "消息通知", tags = SwaggerConstants.API_ALL)
@AllArgsConstructor
public class DogNewsController {
    private final IDogNewsService dogNewsService;
    private final IDogNewsReadService dogNewsReadService;

    /**
     * @Description: 获取未读数字
     * @Param: status
     * @return: IPage<NewsVo>
     * @Author: wph
     * @Date:
     */

    @ApiOperation(value = "获取未读数字", notes = "获取未读数字", tags = SwaggerConstants.API_TZWZ)
    @GetMapping("/num")
    public R<Integer> page() {
        return R.ok(dogNewsService.getNum());
    }

    /**
     * @Description: 消息通知列表
     * @Param: status
     * @return: IPage<AapiNewsVo>
     * @Author: wph
     * @Date:
     */

    @ApiOperation(value = "消息通知列表", notes = "消息通知列表", tags = SwaggerConstants.API_TZWZ)
    @GetMapping("/page")
    public R<IPage<ApiNewsVo>> page(PageParam page) {
        return R.ok(dogNewsService.getApiPageList(page));
    }


    /**
     * @Description: 保存已读消息
     * @Param: apiNewsReadAddDto
     * @return: Boolean
     * @Author: wph
     * @Date:
     */

    @ApiOperation(value = "保存已读消息", notes = "保存已读消息", tags = SwaggerConstants.API_TZWZ)
    @PostMapping("/save")
    public R<Boolean> save(@Valid @RequestBody ApiNewsReadAddDto apiNewsReadAddDto) {
        return R.ok(dogNewsReadService.saveObj(apiNewsReadAddDto));
    }
}
